import { useIntersectionObserver, useIntervalFn } from '@vueuse/core'
import { ref } from 'vue'
export function useObserver(fn) {
  const target = ref(null)
  const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    if (isIntersecting) {
      stop()
      fn()
    }
  })
  return { target }
}

export function useCountDown(startTime) {
  const countTime = ref(0)
  const { pause, resume } = useIntervalFn(() => {
    if (countTime.value <= 0) {
      pause()
      return
    }
    countTime.value--
  }, 1000)
  const start = () => {
    countTime.value = startTime
    resume()
  }
  return { countTime, start, pause, resume }
}
